﻿/************************************************************************************
* Copyright (c) 2019 All Rights Reserved.
*命名空间：Separate.DAL.MySQL
*文件名： MySqlFunction
*创建人： Liebeskind
*创建时间：2019/6/13 14:52:37
*描述
*=====================================================================
*修改标记
*修改时间：2019/6/13 14:52:37
*修改人：Liebeskind
*描述：认为线上的所有对象都是Package，可能是摞，可能是盘。
************************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SqlHelper;
using Commonality.DAL.WZS_SFCS;
using System.Text.RegularExpressions;


namespace Commonality.DAL.MySQL
{
    public static class MySqlFunction
    {
        public static SqlHelper.MySql MySql;
        public static void InitMySQLFunction()
        {
            MySql = new SqlHelper.MySql();
        }
        public static class Node
        {
            //表名
            public static string TabName = "node";
            //表头
            public static string SN = "sn";
            public static string Node_list = "node_list";
            public static string Data_time = "data_time";

            #region 新增
            private static void Node_INSERT(string sn,string node)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");

                    node = node + "   " + DateTime.Now.ToString("MM-dd-HH:mm:ss") + "|";

                    string sql = string.Format("insert into {0} ({1},{2},{3}) values('{4}','{5}','{6}')", TabName,
                                                                                                                            SN, Node_list, Data_time,
                                                                                                                            sn, node, time);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion
            #region 查询
            public static void Node_SELECT(string sn,ref List<string> nodeList)
            {
                nodeList = new List<string>();
                string dict = "";
                string[] list;
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("select {0} from {1} where {2} = '{3}'", Node_list,
                                                                                            TabName,
                                                                                            SN, sn);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        dict = ds.Tables[0].Rows[i][0].ToString();
                    }
                    if (errorMessage != "")
                    {

                    }

                    list = dict.Split(new char[] { '|' });
                    foreach (var item in list)
                    {
                        nodeList.Add(item);
                    }
                }
                catch (Exception ex)
                {

                }

            }
            public static void Node_SELECT(string sn, ref string nodeList)
            {
                nodeList = "";
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("select {0} from {1} where {2} = '{3}'", Node_list,
                                                                                            TabName,
                                                                                            SN, sn);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        nodeList = ds.Tables[0].Rows[i][0].ToString();
                    }
                    if (errorMessage != "")
                    {

                    }
                    
                }
                catch (Exception ex)
                {

                }

            }
            #endregion
            #region “更新”
            public static void Node_UPDATE(string sn, string node)
            {
                List<string> nodeList = new List<string>();
                Node_SELECT(sn, ref nodeList);
                if (nodeList.Count == 1 && nodeList[0] == "")
                {
                    Node_INSERT(sn, node);
                }
                else
                {
                    string list = "";
                    Node_SELECT(sn, ref list);
                    node = list + node + "   " + DateTime.Now.ToString("MM-dd-HH:mm:ss") + "|";
                    try
                    {
                        string errorMessage = "";
                        string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                        string sql = string.Format("UPDATE {0} SET {1} = '{2}' WHERE {3} = '{4}'", TabName,
                                                                                                                                Node_list, node,
                                                                                                                                SN, sn);
                        MySql.UpdateData(sql, out errorMessage);
                        if (errorMessage != "")
                        {

                        }
                    }
                    catch (Exception ex)
                    {

                    }
                }               
            }
            public static Action<string, string> Node_UPDATE_Action = (string sn, string node) => { Node_UPDATE(sn, node); };
            #endregion
        }

        public static class PackageOrientation
        {
            //表名
            public static string TabName = "package_orientation";
            //表头
            public static string Usn_key = "usn_key";

            public static string Orientation = "orientation";
            public static string Message = "message";
            public static string Data_time = "data_time";
            #region 新增
            /// <summary>
            /// 增加-异常摞/盘信息
            /// </summary>
            /// <param name="usn">SN</param>
            /// <param name="orientation">流到方向：0.下行；1.异常1；2.异常2；3.异常3</param>
            /// <param name="package_message">异常信息</param>
            public static void PackageOrientation_INSERT(string usn, int orientation, string package_message)
            {
                PackageOrientation_Delete(usn);

                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("insert into {0} ({1},{2},{3},{4}) values('{5}',{6},'{7}','{8}')", TabName,
                                                                                                                            Usn_key, Orientation, Message, Data_time,
                                                                                                                            usn, orientation, package_message, time);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion

            #region 改
            /// <summary>
            /// 跟新数据
            /// </summary>
            /// <param name="usnKey"></param>
            /// <param name="orientation"></param>
            /// <param name="package_message"></param>
            public static void PackageOrientation_UPDATE(string usnKey, int orientation, string package_message)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("UPDATE {0} SET {1} = '{2}',{3} = '{4}' WHERE {5} = '{6}'", TabName,
                                                                                                                            Orientation, orientation,
                                                                                                                            Message, package_message,
                                                                                                                            Usn_key, usnKey);
                    MySql.UpdateData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }

            public static Action<string, int, string> PackageOrientation_UPDATE_Action = (string usnKey, int orientation, string package_message) =>
            {
                PackageOrientation_UPDATE(usnKey, orientation, package_message);
            };
            #endregion

            #region 查询
            /// <summary>
            /// 查询数据
            /// </summary>
            /// <param name="usnKey"></param>
            /// <param name="orientation"></param>
            /// <param name="package_message"></param>
            public static void PackageOrientation_SELECT(string usnKey, ref int orientation, ref string package_message)
            {
                string[] dict = new string[2] { "-1", "" };
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("select {0},{1} from {2} where {3} = '{4}'", Orientation, Message,
                                                                                                    TabName,
                                                                                                    Usn_key, usnKey);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            dict[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
                orientation = Convert.ToInt16(dict[0]);
                package_message = dict[1];
            }
            #endregion

            #region 删除
            public static void PackageOrientation_Delete(string usn)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("DELETE FROM package_orientation where usn_key = '{0}'",usn);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion
        }
        public static class InputStatistics
        {
            //表名
            public static string TabName = "input_statistics";
            //表头
            public static string Input = "input";
            public static string FailInput = "fail_input";
            public static string MixInput = "mix_input";
            public static string BlockOut = "block_out";
            public static string FM = "fm";
            public static string Foam = "foam";

            public static string Data_time = "data_time";


            #region 新增
            public static void InputStatistics_INSERT()
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("yyyy:MM:dd");
                    string sql = string.Format("insert into {0} ({1},{2},{3}) values('{4}',{5},'{6}')", TabName,
                                                                                                                Input, FailInput, Data_time,
                                                                                                                0, 0,  time);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            public static void InputStatistics_INSERT(int advDay)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.AddDays(advDay).ToString("yyyy:MM:dd");
                    string sql = string.Format("insert into {0} ({1},{2},{3}) values('{4}',{5},'{6}')", TabName,
                                                                                                                Input, FailInput, Data_time,
                                                                                                                0, 0, time);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion
            #region 改
            public static void InputStatistics_UPDATE(int input, int failinput,int mixinput)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("yyyy:MM:dd");
                    string sql = string.Format("UPDATE {0} SET {1} = '{2}',{3} = '{4}',{5} = '{6}' WHERE {7} = '{8}'", TabName,
                                                                                                                                    Input, input,
                                                                                                                                    FailInput, failinput,
                                                                                                                                    MixInput,mixinput,
                                                                                                                                    Data_time, time);
                    MySql.UpdateData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            public static void InputStatistics_Block_UPDATE(int blockinput)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("yyyy:MM:dd");
                    string sql = string.Format("UPDATE {0} SET {1} = '{2}' WHERE {3} = '{4}'", TabName,
                                                                                                BlockOut, blockinput,
                                                                                                Data_time, time);
                    MySql.UpdateData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }

            public static void InputStatistics_FM_UPDATE(int fm)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("yyyy:MM:dd");
                    string sql = string.Format("UPDATE {0} SET {1} = '{2}' WHERE {3} = '{4}'", TabName,
                                                                                                FM, fm,
                                                                                                Data_time, time);
                    MySql.UpdateData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            public static void InputStatistics_Foam_UPDATE(int foam)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("yyyy:MM:dd");
                    string sql = string.Format("UPDATE {0} SET {1} = '{2}' WHERE {3} = '{4}'", TabName,
                                                                                                Foam, foam,
                                                                                                Data_time, time);
                    MySql.UpdateData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion
            #region 查询
            public static void InputStatistics_SELECT(ref int input,ref int failinput, ref int mixinput, ref int blockout)
            {
                string[] dict = new string[4] { "0", "0" ,"0","0"};
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("yyyy:MM:dd");
                    string sql = string.Format("select {0},{1},{2},{3} from {4} where {5} = '{6}'", Input, FailInput, MixInput, BlockOut,
                                                                                                    TabName,
                                                                                                    Data_time, time);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            dict[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
                input = Convert.ToInt32(dict[0]);
                failinput = Convert.ToInt32(dict[1]);
                mixinput = Convert.ToInt32(dict[2]);
                blockout = Convert.ToInt32(dict[3]);
            }
            public static void InputStatistics_SELECT(ref int fm, ref int foam)
            {
                string[] dict = new string[2] { "0", "0" };
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("yyyy:MM:dd");
                    string sql = string.Format("select {0},{1} from {2} where {3} = '{4}'", FM, Foam,
                                                                                                    TabName,
                                                                                                    Data_time, time);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            dict[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
                fm = Convert.ToInt32(dict[0]);
                foam = Convert.ToInt32(dict[1]);
            }

            public static string InputStatistics_SELECT(string time, ref int input, ref int failinput,ref int mixinput,ref int blockout)
            {
                string[] dict = new string[4] { "0", "0", "0", "0"};
                string errorMessage = "";
                try
                {
                    
                    string sql = string.Format("select {0},{1},{2},{3} from {4} where {5} = '{6}'", Input, FailInput, MixInput, BlockOut,
                                                                                                            TabName,
                                                                                                            Data_time, time);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            dict[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }
                    if (errorMessage != "")
                    {
                        
                    }
                }
                catch (Exception ex)
                {

                }
                input = Convert.ToInt32(dict[0]);
                failinput = Convert.ToInt32(dict[1]);
                mixinput = Convert.ToInt32(dict[2]);
                blockout = Convert.ToInt32(dict[3]);

                return errorMessage;
            }
            public static string InputStatistics_SELECT(string time, ref int fm, ref int foam)
            {
                string[] dict = new string[2] { "0", "0" };
                string errorMessage = "";
                try
                {

                    string sql = string.Format("select {0},{1} from {2} where {3} = '{4}'", FM, Foam,
                                                                                                            TabName,
                                                                                                            Data_time, time);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            dict[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
                fm = Convert.ToInt32(dict[0]);
                foam = Convert.ToInt32(dict[1]);

                return errorMessage;
            }
            #endregion
        }

        public static class TrayCellDataList
        {
            //表名
            public static string TabName = "traycell_datalist";
            //表头
            public static string Usn_key_a = "usn_key_a";
            public static string Usninfo_a = "usninfo_a";
            public static string Bin_a = "bin_a";

            public static string Usn_key_b = "usn_key_b";
            public static string Usninfo_b = "usninfo_b";
            public static string Bin_b = "bin_b";

            public static string Eigenvector = "eigenvector";

            public static string Data_time = "data_time";
            #region 新增
            public static void TrayCellDataList_INSERT_(ProductCellData cella, ProductCellData cellb)
            {
                string usn_a = cella.usn;
                string usn_b = cellb.usn;

                string usninfo_a = string.Join("|", cella.usnInfo);
                string usninfo_b = string.Join("|", cellb.usnInfo);

                string bin_a = string.Join("|", cella.bin);
                string bin_b = string.Join("|", cellb.bin);

                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("insert into {0} ({1},{2},{3},{4},{5},{6},{7}) values('{8}','{9}','{10}','{11}','{12}','{13}','{14}')",
                                                                                                        TabName,
                                                                                                        Usn_key_a, Usninfo_a, Bin_a, Usn_key_b, Usninfo_b, Bin_b, Data_time,
                                                                                                        usn_a, usninfo_a, bin_a, usn_b, usninfo_b, bin_b, time);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            public static void TrayCellDataList_INSERT(ProductCellData cella, ProductCellData cellb)
            {
                string usn_a = cella.usn;
                string usn_b = cellb.usn;

                string usninfo_a = string.Join("|", cella.usnInfo);
                string usninfo_b = string.Join("|", cellb.usnInfo);

                string bin_a = string.Join("|", cella.bin);
                string bin_b = string.Join("|", cellb.bin);

                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("insert into {0} ({1},{2},{3},{4},{5}) values('{6}','{7}','{8}','{9}','{10}')",
                                                                                                        TabName,
                                                                                                        Usn_key_a, Usninfo_a, Usn_key_b, Usninfo_b, Data_time,
                                                                                                        usn_a, usninfo_a, usn_b, usninfo_b, time);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion

            #region 改
            /// <summary>
            /// 更新tray的类型特征向量
            /// </summary>
            /// <param name="usnKeya"></param>
            /// <param name="usnKeyb"></param>
            /// <param name="eigenvector"></param>
            public static void TrayCellDataList_Eigenvector_UPDATE(string usnKeya, string usnKeyb, ref string eigenvector)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("UPDATE {0} SET {1} = '{2}' WHERE {3} = '{4}' or {5} = '{6}'", TabName,
                                                                                                                            Eigenvector, eigenvector,
                                                                                                                            Usn_key_a, usnKeya,
                                                                                                                            Usn_key_b, usnKeyb);
                    MySql.UpdateData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion

            #region 查询
            public static void TrayCellDataList_SELECT_(string usnKeya, string usnKeyb, ref ProductCellData cella)
            {
                string[] dict = new string[2];
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("select {0},{1} from {2} where {3} = '{4}' or {5} = '{6}'", Usninfo_a, Bin_a,
                                                                                                    TabName,
                                                                                                    Usn_key_a, usnKeya,
                                                                                                    Usn_key_b, usnKeyb);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            dict[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
                cella.usnInfo = dict[0].Split(new char[] { '|' }); ;
                cella.bin = dict[1].Split(new char[] { '|' }); ;
            }
            public static void TrayCellDataList_SELECT(string usnKeya, string usnKeyb, ref ProductCellData cella)
            {
                string[] dict = new string[2];
                try
                {
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("select {0} from {1} where {2} = '{3}' or {4} = '{5}'", Usninfo_a,
                                                                                                    TabName,
                                                                                                    Usn_key_a, usnKeya,
                                                                                                    Usn_key_b, usnKeyb);

                    string errorMessage;
                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            dict[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception)
                {

                }
                cella.usnInfo = dict[0].Split(new char[] { '|' }); ;
                cella.bin = new string[1] { "" };
            }
            public static void TrayCellDataList_SN_SELECT(string usnKeya, ref string usnb)
            {
                string[] dict = new string[1];
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("select {0} from {1} where {2} = '{3}'", Usn_key_b,
                                                                                                    TabName,
                                                                                                    Usn_key_a, usnKeya);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            dict[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
                usnb = dict[0];
            }
            /// <summary>
            /// 查询tray的类型特征向量
            /// </summary>
            /// <param name="usnKeya"></param>
            /// <param name="usnKeyb"></param>
            /// <param name="eigenvector"></param>
            public static void TrayCellDataList__Eigenvector_SELECT(string usnKeya, string usnKeyb, ref string eigenvector)
            {
                string[] dict = new string[1] { "" };
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("select {0} from {1} where {2} = '{3}' or {4} = '{5}'", Eigenvector,
                                                                                                    TabName,
                                                                                                    Usn_key_a, usnKeya,
                                                                                                    Usn_key_b, usnKeyb);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            dict[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
                eigenvector = dict[0];
            }
            #endregion

            #region 删除

            #endregion
        }

        public static class PacketData
        {
            //表名
            public static string TabName = "packet_data";
            //表头
            public static string Usn1 = "usn1";
            public static string Usn2 = "usn2";
            public static string Usn3 = "usn3";
            public static string Usn4 = "usn4";
            public static string Usn5 = "usn5";
            public static string Usn6 = "usn6";
            public static string Usn7 = "usn7";
            public static string Usn8 = "usn8";
            public static string Usn9 = "usn9";
            public static string Usn10 = "usn10";

            public static string Usn11 = "usn11";
            public static string Usn12 = "usn12";
            public static string Usn13 = "usn13";
            public static string Usn14 = "usn14";
            public static string Usn15 = "usn15";
            public static string Usn16 = "usn16";
            public static string Usn17 = "usn17";
            public static string Usn18 = "usn18";
            public static string Usn19 = "usn19";
            public static string Usn20 = "usn20";

            public static string CaverNumber = "caver_number";

            public static string Usn_list_count = "usn_list_count";

            public static string Data_time = "data_time";
            #region 新增
            public static void PacketData_INSERT(List<string> usnList, string caverNumber)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("insert into {0} ({1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20}, {21},{22},{23}) values ('{24}','{25}','{26}','{27}','{28}','{29}','{30}','{31}','{32}','{33}','{34}','{35}','{36}','{37}','{38}','{39}','{40}','{41}','{42}','{43}','{44}','{45}','{46}')",
                    TabName,
                    Usn1, Usn2, Usn3, Usn4, Usn5, Usn6, Usn7, Usn8, Usn9, Usn10,
                    Usn11, Usn12, Usn13, Usn14, Usn15, Usn16, Usn17, Usn18, Usn19, Usn20, Usn_list_count, Data_time, CaverNumber,
                    usnList[0].Replace("\r\n", ""), usnList[1].Replace("\r\n", ""), usnList[2].Replace("\r\n", ""), usnList[3].Replace("\r\n", ""), usnList[4].Replace("\r\n", ""), usnList[5].Replace("\r\n", ""), usnList[6].Replace("\r\n", ""), usnList[7].Replace("\r\n", ""), usnList[8].Replace("\r\n", ""), usnList[9].Replace("\r\n", ""), usnList[10].Replace("\r\n", ""),
                    usnList[11].Replace("\r\n", ""), usnList[12].Replace("\r\n", ""), usnList[13].Replace("\r\n", ""), usnList[14].Replace("\r\n", ""), usnList[15].Replace("\r\n", ""), usnList[16].Replace("\r\n", ""), usnList[17].Replace("\r\n", ""), usnList[18].Replace("\r\n", ""), usnList[19].Replace("\r\n", ""), usnList.Count, time, caverNumber);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }

            public static Action<List<string>, string> PacketData_INSERT_Action = (List<string> usnList, string caverNumber) =>
            {
                PacketData_INSERT(usnList, caverNumber);
            };
            #endregion
            #region 删除

            #endregion



            public static class Check_PacketData
            {
                public static void Packet_Data_Check(string usnkey, ref string[] data)
                {
                    string[] ret = new string[21];
                    try
                    {
                        string errormessage;
                        string sql = string.Format("select usn1,usn2,usn3,usn4,usn5,usn6,usn7,usn8,usn9,usn10,usn11,usn12,usn13,usn14,usn15,usn16,usn17,usn18,usn19,usn20,usn_list_count from packet_data where usn1 = {0} or usn2 = {0} or usn3 = {0} or usn4 = {0} or usn5 = {0} or usn6 = {0} or usn7 = {0} or usn8 = {0} or usn9 = {0} or usn10 = {0} or usn11 = {0} or usn12 = {0} or usn13 = {0} or usn14 = {0} or usn15 = {0} or usn16 = {0} or usn17 = {0} or usn18 = {0} or usn19 = {0} or usn20 = {0}", usnkey);
                        DataSet ds = MySql.runSQL_getDataset(sql, out errormessage);
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                            {
                                ret[j] = ds.Tables[0].Rows[i][j].ToString();
                            }
                        }

                    }
                    catch (Exception ex)
                    {

                    }
                    data = ret;
                }
            }

            public static class DELETE_PacketData
            {
                public static void Packet_Data_Delete(string usnkey)
                {
                    try
                    {
                        string errorMessage = "";
                        string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                        string sql = string.Format("DELETE FROM packet_data where usn1 = {0} or usn2 = {0} or usn3 = {0} or usn4 = {0} or usn5 = {0} or usn6 = {0} or usn7 = {0} or usn8 = {0} or usn9 = {0} or usn10 = {0} or usn11 = {0} or usn12 = {0} or usn13 = {0} or usn14 = {0} or usn15 = {0} or usn16 = {0} or usn17 = {0} or usn18 = {0} or usn19 = {0} or usn20 = {0}",
                        usnkey.Replace("\r\n", ""));
                        MySql.InsertData(sql, out errorMessage);
                        if (errorMessage != "")
                        {

                        }
                    }
                    catch (Exception ex)
                    {

                    }
                }
            }
        }

        public static class AttentionPnData
        {
            //表名
            public static string TabName = "attention_pn_data";

            //表头
            public static string Pn = "pn";
            public static string Mo = "mo";
            public static string Project = "project";
            public static string Birthtime = "birthtime";
            public static string Active = "active";

            public static string Data_time = "data_time";

            #region 新增
            public static void AttentionPnData_INSERT(string pn, string mo, string project, string birthtime)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("insert into {0} ({1},{2},{3},{4},{5},{6})values('{7}','{8}','{9}','{10}','{11}','{12}')",
                                                                                                                        TabName,
                                                                                                                        Pn, Mo, Project, Birthtime, Active, Data_time,
                                                                                                                        pn, mo, project, birthtime, "1", time);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion
            #region 查询
            /// <summary>
            /// 加载关注的PN集合
            /// </summary>
            /// <param name="pnData"></param>
            public static void AttentionPnData_SELECT(ref List<string> pnData)
            {
                pnData = new List<string>();
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("select {0} from {1}", Pn, TabName);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            pnData.Add(ds.Tables[0].Rows[i][j].ToString());
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            /// <summary>
            /// 查询此PN的总规划量(忽视MO的分别)
            /// </summary>
            /// <param name="pn"></param>
            /// <param name="project"></param>
            public static void AttentionPnData_Project_SELECT(string pn, ref int project)
            {
                List<string> ProjectList = new List<string>();
                project = 0;
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("select {0} from {1} WHERE {2} = '{3}'", Project, TabName, Pn, pn);
                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            ProjectList.Add(ds.Tables[0].Rows[i][j].ToString());
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
                foreach (var item in ProjectList)
                {
                    if (Regex.IsMatch(item, @"^[+-]?\d*$") && item != "")
                    {
                        project = project + Convert.ToInt16(item.ToString());
                    }
                }
            }
            /// <summary>
            /// 索引关注的料号包含的已经被记录的MO
            /// </summary>
            /// <param name="pn"></param>
            /// <param name="moData"></param>
            public static void AttentionPnData_Mo_SELECT(string pn, ref List<string> moData)
            {
                moData = new List<string>();
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("select {0} from {1} WHERE {2} = '{3}'", Mo, TabName, Pn, pn);

                    DataSet ds = MySql.runSQL_getDataset(sql, out errorMessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            moData.Add(ds.Tables[0].Rows[i][j].ToString());
                        }
                    }
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion
            #region 改

            #endregion
            #region 删除
            /// <summary>
            /// 删除过时的PN
            /// </summary>
            /// <param name="pn"></param>
            public static void AttentionPnData_Pn_DELETE(string pn)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("DELETE FROM {0} WHERE {1} = '{2}';",
                    TabName,
                    Pn, pn);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion
        }

        public static class BufferUsndata
        {
            //表名
            public static string TabName = "buffer_usndata";

            //表头
            public static string Buffer_coord = "buffer_coord";             //固定值作为对应仓的索引
            public static string Usn_1_date = "usn_1_date";
            public static string Usn_2_date = "usn_2_date";
            public static string Usn_3_date = "usn_3_date";
            public static string Usn_4_date = "usn_4_date";
            public static string Usn_5_date = "usn_5_date";
            public static string Usn_6_date = "usn_6_date";
            public static string Usn_7_date = "usn_7_date";
            public static string Usn_8_date = "usn_8_date";
            public static string Usn_9_date = "usn_9_date";
            public static string Usn_10_date = "usn_10_date";
            public static string Usn_11_date = "usn_11_date";
            public static string Usn_12_date = "usn_12_date";
            public static string Usn_13_date = "usn_13_date";
            public static string Usn_14_date = "usn_14_date";
            public static string Usn_15_date = "usn_15_date";
            public static string Usn_16_date = "usn_16_date";
            public static string Usn_17_date = "usn_17_date";
            public static string Usn_18_date = "usn_18_date";
            public static string Usn_19_date = "usn_19_date";
            public static string Usn_20_date = "usn_20_date";

            public static string Data_time = "data_time";

            #region 改
            public static void BufferUsndata_UPDATE(int CaverNum, int UsnNum, string usn)
            {
                string Usn_i_data = "";
                Usn_i_data = "usn_" + UsnNum + "_date";

                string Buffer_coord_i = "";
                switch (CaverNum)
                {
                    #region A1
                    case 111:
                        Buffer_coord_i = "A11";
                        break;
                    case 112:
                        Buffer_coord_i = "A12";
                        break;
                    case 113:
                        Buffer_coord_i = "A13";
                        break;
                    case 114:
                        Buffer_coord_i = "A14";
                        break;
                    case 115:
                        Buffer_coord_i = "A15";
                        break;
                    #endregion
                    #region A2
                    case 121:
                        Buffer_coord_i = "A21";
                        break;
                    case 122:
                        Buffer_coord_i = "A22";
                        break;
                    case 123:
                        Buffer_coord_i = "A23";
                        break;
                    case 124:
                        Buffer_coord_i = "A24";
                        break;
                    case 125:
                        Buffer_coord_i = "A25";
                        break;
                    #endregion
                    #region A3
                    case 131:
                        Buffer_coord_i = "A31";
                        break;
                    case 132:
                        Buffer_coord_i = "A32";
                        break;
                    case 133:
                        Buffer_coord_i = "A33";
                        break;
                    case 134:
                        Buffer_coord_i = "A34";
                        break;
                    case 135:
                        Buffer_coord_i = "A35";
                        break;
                    #endregion


                    #region B1
                    case 211:
                        Buffer_coord_i = "B11";
                        break;
                    case 212:
                        Buffer_coord_i = "B12";
                        break;
                    case 213:
                        Buffer_coord_i = "B13";
                        break;
                    case 214:
                        Buffer_coord_i = "B14";
                        break;
                    case 215:
                        Buffer_coord_i = "B15";
                        break;
                    #endregion
                    #region B2
                    case 221:
                        Buffer_coord_i = "B21";
                        break;
                    case 222:
                        Buffer_coord_i = "B22";
                        break;
                    case 223:
                        Buffer_coord_i = "B23";
                        break;
                    case 224:
                        Buffer_coord_i = "B24";
                        break;
                    case 225:
                        Buffer_coord_i = "B25";
                        break;
                    #endregion
                    #region B3
                    case 231:
                        Buffer_coord_i = "B31";
                        break;
                    case 232:
                        Buffer_coord_i = "B32";
                        break;
                    case 233:
                        Buffer_coord_i = "B33";
                        break;
                    case 234:
                        Buffer_coord_i = "B34";
                        break;
                    case 235:
                        Buffer_coord_i = "B35";
                        break;
                        #endregion
                }

                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("UPDATE {0} SET {1} = '{2}' WHERE {3} = '{4}'", TabName,
                                                                                                Usn_i_data, usn,
                                                                                                Buffer_coord, Buffer_coord_i);
                    MySql.UpdateData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }

            #endregion
            #region 删
            public static void BufferUsndata_DELETE(int CaverNum)
            {
                string Buffer_coord_i = "";
                switch (CaverNum)
                {
                    #region A1
                    case 111:
                        Buffer_coord_i = "A11";
                        break;
                    case 112:
                        Buffer_coord_i = "A12";
                        break;
                    case 113:
                        Buffer_coord_i = "A13";
                        break;
                    case 114:
                        Buffer_coord_i = "A14";
                        break;
                    case 115:
                        Buffer_coord_i = "A15";
                        break;
                    #endregion
                    #region A2
                    case 121:
                        Buffer_coord_i = "A21";
                        break;
                    case 122:
                        Buffer_coord_i = "A22";
                        break;
                    case 123:
                        Buffer_coord_i = "A23";
                        break;
                    case 124:
                        Buffer_coord_i = "A24";
                        break;
                    case 125:
                        Buffer_coord_i = "A25";
                        break;
                    #endregion
                    #region A3
                    case 131:
                        Buffer_coord_i = "A31";
                        break;
                    case 132:
                        Buffer_coord_i = "A32";
                        break;
                    case 133:
                        Buffer_coord_i = "A33";
                        break;
                    case 134:
                        Buffer_coord_i = "A34";
                        break;
                    case 135:
                        Buffer_coord_i = "A35";
                        break;
                    #endregion


                    #region B1
                    case 211:
                        Buffer_coord_i = "B11";
                        break;
                    case 212:
                        Buffer_coord_i = "B12";
                        break;
                    case 213:
                        Buffer_coord_i = "B13";
                        break;
                    case 214:
                        Buffer_coord_i = "B14";
                        break;
                    case 215:
                        Buffer_coord_i = "B15";
                        break;
                    #endregion
                    #region B2
                    case 221:
                        Buffer_coord_i = "B21";
                        break;
                    case 222:
                        Buffer_coord_i = "B22";
                        break;
                    case 223:
                        Buffer_coord_i = "B23";
                        break;
                    case 224:
                        Buffer_coord_i = "B24";
                        break;
                    case 225:
                        Buffer_coord_i = "B25";
                        break;
                    #endregion
                    #region B3
                    case 231:
                        Buffer_coord_i = "B31";
                        break;
                    case 232:
                        Buffer_coord_i = "B32";
                        break;
                    case 233:
                        Buffer_coord_i = "B33";
                        break;
                    case 234:
                        Buffer_coord_i = "B34";
                        break;
                    case 235:
                        Buffer_coord_i = "B35";
                        break;
                        #endregion
                }

                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("UPDATE {0} SET {1} = '',{2} = '',{3} = '',{4} = '',{5} = '',{6} = '',{7} = '',{8} = '',{9} = '',{10} = ''" +
                                                            "{11} = '',{12} = '',{13} = '',{14} = '',{15} = '',{16} = '',{17} = '',{18} = '',{19} = '',{20} = ''" +
                                                            "WHERE {21} = '{22}'",
                        TabName,
                        Usn_1_date, Usn_2_date, Usn_3_date, Usn_4_date, Usn_5_date, Usn_6_date, Usn_7_date, Usn_8_date, Usn_9_date, Usn_10_date, Usn_11_date, Usn_12_date, Usn_13_date, Usn_14_date, Usn_15_date, Usn_16_date, Usn_17_date, Usn_18_date, Usn_19_date, Usn_20_date,

                        Buffer_coord, Buffer_coord_i);
                    MySql.UpdateData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion
        }
        public static class BufferUsndataProgramme
        {
            //表名
            public static string TabName = "buffer_usndata_programme";

            //表头
            public static string Buffer_coord = "buffer_coord";             //固定值作为对应仓的索引
            public static string Usn_1_date = "usn_1_date";
            public static string Usn_2_date = "usn_2_date";
            public static string Usn_3_date = "usn_3_date";
            public static string Usn_4_date = "usn_4_date";
            public static string Usn_5_date = "usn_5_date";
            public static string Usn_6_date = "usn_6_date";
            public static string Usn_7_date = "usn_7_date";
            public static string Usn_8_date = "usn_8_date";
            public static string Usn_9_date = "usn_9_date";
            public static string Usn_10_date = "usn_10_date";
            public static string Usn_11_date = "usn_11_date";
            public static string Usn_12_date = "usn_12_date";
            public static string Usn_13_date = "usn_13_date";
            public static string Usn_14_date = "usn_14_date";
            public static string Usn_15_date = "usn_15_date";
            public static string Usn_16_date = "usn_16_date";
            public static string Usn_17_date = "usn_17_date";
            public static string Usn_18_date = "usn_18_date";
            public static string Usn_19_date = "usn_19_date";
            public static string Usn_20_date = "usn_20_date";

            public static string Data_time = "data_time";

            #region 改
            public static void BufferUsndataProgramme_UPDATE(int CaverNum, int UsnNum, string usn)
            {
                string Usn_i_data = "";
                Usn_i_data = "usn_" + UsnNum + "_date";

                string Buffer_coord_i = "";
                switch (CaverNum)
                {
                    #region A1
                    case 111:
                        Buffer_coord_i = "A11";
                        break;
                    case 112:
                        Buffer_coord_i = "A12";
                        break;
                    case 113:
                        Buffer_coord_i = "A13";
                        break;
                    case 114:
                        Buffer_coord_i = "A14";
                        break;
                    case 115:
                        Buffer_coord_i = "A15";
                        break;
                    #endregion
                    #region A2
                    case 121:
                        Buffer_coord_i = "A21";
                        break;
                    case 122:
                        Buffer_coord_i = "A22";
                        break;
                    case 123:
                        Buffer_coord_i = "A23";
                        break;
                    case 124:
                        Buffer_coord_i = "A24";
                        break;
                    case 125:
                        Buffer_coord_i = "A25";
                        break;
                    #endregion
                    #region A3
                    case 131:
                        Buffer_coord_i = "A31";
                        break;
                    case 132:
                        Buffer_coord_i = "A32";
                        break;
                    case 133:
                        Buffer_coord_i = "A33";
                        break;
                    case 134:
                        Buffer_coord_i = "A34";
                        break;
                    case 135:
                        Buffer_coord_i = "A35";
                        break;
                    #endregion


                    #region B1
                    case 211:
                        Buffer_coord_i = "B11";
                        break;
                    case 212:
                        Buffer_coord_i = "B12";
                        break;
                    case 213:
                        Buffer_coord_i = "B13";
                        break;
                    case 214:
                        Buffer_coord_i = "B14";
                        break;
                    case 215:
                        Buffer_coord_i = "B15";
                        break;
                    #endregion
                    #region B2
                    case 221:
                        Buffer_coord_i = "B21";
                        break;
                    case 222:
                        Buffer_coord_i = "B22";
                        break;
                    case 223:
                        Buffer_coord_i = "B23";
                        break;
                    case 224:
                        Buffer_coord_i = "B24";
                        break;
                    case 225:
                        Buffer_coord_i = "B25";
                        break;
                    #endregion
                    #region B3
                    case 231:
                        Buffer_coord_i = "B31";
                        break;
                    case 232:
                        Buffer_coord_i = "B32";
                        break;
                    case 233:
                        Buffer_coord_i = "B33";
                        break;
                    case 234:
                        Buffer_coord_i = "B34";
                        break;
                    case 235:
                        Buffer_coord_i = "B35";
                        break;
                        #endregion
                }

                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("UPDATE {0} SET {1} = '{2}' WHERE {3} = '{4}'", TabName,
                                                                                                Usn_i_data, usn,
                                                                                                Buffer_coord, Buffer_coord_i);
                    MySql.UpdateData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }

            #endregion
            #region 删
            public static void BufferUsndataProgramme_DELETE(int CaverNum)
            {
                string Null = "";
                string Buffer_coord_i = "";
                switch (CaverNum)
                {
                    #region A1
                    case 111:
                        Buffer_coord_i = "A11";
                        break;
                    case 112:
                        Buffer_coord_i = "A12";
                        break;
                    case 113:
                        Buffer_coord_i = "A13";
                        break;
                    case 114:
                        Buffer_coord_i = "A14";
                        break;
                    case 115:
                        Buffer_coord_i = "A15";
                        break;
                    #endregion
                    #region A2
                    case 121:
                        Buffer_coord_i = "A21";
                        break;
                    case 122:
                        Buffer_coord_i = "A22";
                        break;
                    case 123:
                        Buffer_coord_i = "A23";
                        break;
                    case 124:
                        Buffer_coord_i = "A24";
                        break;
                    case 125:
                        Buffer_coord_i = "A25";
                        break;
                    #endregion
                    #region A3
                    case 131:
                        Buffer_coord_i = "A31";
                        break;
                    case 132:
                        Buffer_coord_i = "A32";
                        break;
                    case 133:
                        Buffer_coord_i = "A33";
                        break;
                    case 134:
                        Buffer_coord_i = "A34";
                        break;
                    case 135:
                        Buffer_coord_i = "A35";
                        break;
                    #endregion


                    #region B1
                    case 211:
                        Buffer_coord_i = "B11";
                        break;
                    case 212:
                        Buffer_coord_i = "B12";
                        break;
                    case 213:
                        Buffer_coord_i = "B13";
                        break;
                    case 214:
                        Buffer_coord_i = "B14";
                        break;
                    case 215:
                        Buffer_coord_i = "B15";
                        break;
                    #endregion
                    #region B2
                    case 221:
                        Buffer_coord_i = "B21";
                        break;
                    case 222:
                        Buffer_coord_i = "B22";
                        break;
                    case 223:
                        Buffer_coord_i = "B23";
                        break;
                    case 224:
                        Buffer_coord_i = "B24";
                        break;
                    case 225:
                        Buffer_coord_i = "B25";
                        break;
                    #endregion
                    #region B3
                    case 231:
                        Buffer_coord_i = "B31";
                        break;
                    case 232:
                        Buffer_coord_i = "B32";
                        break;
                    case 233:
                        Buffer_coord_i = "B33";
                        break;
                    case 234:
                        Buffer_coord_i = "B34";
                        break;
                    case 235:
                        Buffer_coord_i = "B35";
                        break;
                        #endregion
                }

                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("UPDATE {0} SET {1} = '',{2} = '',{3} = '',{4} = '',{5} = '',{6} = '',{7} = '',{8} = '',{9} = '',{10} = ''" +
                                                            "{11} = '',{12} = '',{13} = '',{14} = '',{15} = '',{16} = '',{17} = '',{18} = '',{19} = '',{20} = ''" +
                                                            "WHERE {21} = '{22}'",
                        TabName,
                        Usn_1_date, Usn_2_date, Usn_3_date, Usn_4_date, Usn_5_date, Usn_6_date, Usn_7_date, Usn_8_date, Usn_9_date, Usn_10_date, Usn_11_date, Usn_12_date, Usn_13_date, Usn_14_date, Usn_15_date, Usn_16_date, Usn_17_date, Usn_18_date, Usn_19_date, Usn_20_date,

                        Buffer_coord, Buffer_coord_i);
                    MySql.UpdateData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }
            #endregion
        }

        /// <summary>
        /// 包装段，包
        /// </summary>
        public static class PacketData_P
        {
            //表名
            public static string TabName = "packet_data_p";
            //表头
            public static string Usn1 = "usn1";
            public static string Usn2 = "usn2";
            public static string Usn3 = "usn3";
            public static string Usn4 = "usn4";
            public static string Usn5 = "usn5";
            public static string Usn6 = "usn6";
            public static string Usn7 = "usn7";
            public static string Usn8 = "usn8";
            public static string Usn9 = "usn9";
            public static string Usn10 = "usn10";

            public static string Usn11 = "usn11";
            public static string Usn12 = "usn12";
            public static string Usn13 = "usn13";
            public static string Usn14 = "usn14";
            public static string Usn15 = "usn15";
            public static string Usn16 = "usn16";
            public static string Usn17 = "usn17";
            public static string Usn18 = "usn18";
            public static string Usn19 = "usn19";
            public static string Usn20 = "usn20";



            public static string Usn_list_count = "usn_list_count";

            public static string Data_time = "data_time";
            #region 新增
            public static void PacketData_INSERT_P(List<string> usnList)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("insert into {0} ({1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20}, {21},{22}) values ('{23}','{24}','{25}','{26}','{27}','{28}','{29}','{30}','{31}','{32}','{33}','{34}','{35}','{36}','{37}','{38}','{39}','{40}','{41}','{42}','{43}','{44}')",
                    TabName,
                    Usn1, Usn2, Usn3, Usn4, Usn5, Usn6, Usn7, Usn8, Usn9, Usn10,
                    Usn11, Usn12, Usn13, Usn14, Usn15, Usn16, Usn17, Usn18, Usn19, Usn20, Usn_list_count, Data_time,
                    usnList[0], usnList[1], usnList[2], usnList[3], usnList[4], usnList[5], usnList[6], usnList[7], usnList[8], usnList[9], usnList[10],
                    usnList[11], usnList[12], usnList[13], usnList[14], usnList[15], usnList[16], usnList[17], usnList[18], usnList[19], usnList.Count, time);
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {


                }

            }
            #endregion

            #region 查询
            public static void Packet_Data_Check_P(string usnkey, ref string[] data)
            {
                string[] ret = new string[21];
                try
                {
                    string errormessage;
                    string sql = string.Format("select usn1,usn2,usn3,usn4,usn5,usn6,usn7,usn8,usn9,usn10,usn11,usn12,usn13,usn14,usn15,usn16,usn17,usn18,usn19,usn20,usn_list_count from packet_data_p where usn1 = {0} or usn2 = {0} or usn3 = {0} or usn4 = {0} or usn5 = {0} or usn6 = {0} or usn7 = {0} or usn8 = {0} or usn9 = {0} or usn10 = {0} or usn11 = {0} or usn12 = {0} or usn13 = {0} or usn14 = {0} or usn15 = {0} or usn16 = {0} or usn17 = {0} or usn18 = {0} or usn19 = {0} or usn20 = {0}", usnkey);
                    DataSet ds = MySql.runSQL_getDataset(sql, out errormessage);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                        {
                            ret[j] = ds.Tables[0].Rows[i][j].ToString();
                        }
                    }

                }
                catch (Exception ex)
                {

                }
                data = ret;
            }
            #endregion

            #region 删除
            public static void Packet_Data_Delete_P(string usnkey)
            {
                try
                {
                    string errorMessage = "";
                    string time = DateTime.Now.ToString("MM:dd:HH:mm:ss");
                    string sql = string.Format("DELETE FROM packet_data_p where usn1 = {0} or usn2 = {0} or usn3 = {0} or usn4 = {0} or usn5 = {0} or usn6 = {0} or usn7 = {0} or usn8 = {0} or usn9 = {0} or usn10 = {0} or usn11 = {0} or usn12 = {0} or usn13 = {0} or usn14 = {0} or usn15 = {0} or usn16 = {0} or usn17 = {0} or usn18 = {0} or usn19 = {0} or usn20 = {0}",
                    usnkey.Replace("\r\n", ""));
                    MySql.InsertData(sql, out errorMessage);
                    if (errorMessage != "")
                    {

                    }
                }
                catch (Exception ex)
                {

                }
            }

            #endregion
        }
    }
}
